<?php

declare(strict_types=1);

/**
 * en控制器公共类(基础类)文件
 */

namespace app\controller\en;

use think\App;
use think\facade\View;
use app\model\System as SystemModel;
use app\model\Category as CategoryModel;

use app\BaseController;

/**
 * 控制器基础类
 *
 * @category index
 * @package  Controller
 * @author   huwhois <huwhois@163.com>
 */
class Base extends BaseController
{
    public function __construct(App $app)
    {
        parent::__construct($app);

        View::engine()->layout('en/layout');

        $this->system = SystemModel::find(1)->toArray();

        View::assign('system', $this->system);

        $list = CategoryModel::field('id, parent_id, name, name_en, url, type')->where('is_nav', 1)->cache(false)->order('sort asc, id asc')->select();

        $categories = list_tree($list, 'id', 'parent_id');

        View::assign('categories', $categories);
    }

    // 404 页面
    public function notFound($msg = '')
    {
        View::engine()->layout(false);

        $filename = $this->app->getRootPath() . "view/en" . DIRECTORY_SEPARATOR . "404.html";

        return View::fetch($filename, ['msg' => $msg]);
    }

}
